package com.tjmc.recruit.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tjmc.recruit.admin.api.entity.PlatUserTagConf;
import com.tjmc.recruit.admin.api.entity.PlatformUserInfoEntity;
import com.tjmc.recruit.admin.service.PlatUserTagConfService;
import com.tjmc.recruit.admin.service.PlatformUserInfoService;
import com.tjmc.recruit.common.core.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/platUserTag")
@RequiredArgsConstructor
@Tag(description = "platUserTag", name = "平台用户标签管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PlatUserTagController {
    private final PlatUserTagConfService platUserTagConfService;
    private final PlatformUserInfoService platformUserInfoService;

    @GetMapping("/page")
    @Operation(description = "分页查询", summary = "分页查询")
    public R getList(@ParameterObject Page page, @ParameterObject PlatUserTagConf platUserTagConf) {
        LambdaQueryWrapper<PlatUserTagConf> wrapper = Wrappers.lambdaQuery(platUserTagConf);
        return R.ok(platUserTagConfService.page(page, wrapper));
    }

    @GetMapping("/getPageByUserId/{accountId}")
    @Operation(description = "查询指定用户标签列表", summary = "查询指定用户标签列表")
    public R getCurrentUser(@PathVariable Long accountId, @ParameterObject Page page) {
        PlatformUserInfoEntity userInfo = platformUserInfoService.getById(accountId);
        if (userInfo == null) {
            return R.failed("未查询到用户信息");
        }
        return R.ok(platUserTagConfService.page(page, Wrappers.<PlatUserTagConf>lambdaQuery().eq(PlatUserTagConf::getAccountId, accountId)));
    }

    @PostMapping("")
    @Operation(description = "新增标签", summary = "新增标签")
    public R save(@RequestBody PlatUserTagConf platUserTagConf) {
        return R.ok(platUserTagConfService.save(platUserTagConf));
    }

    @PutMapping("")
    @Operation(description = "修改标签", summary = "修改标签")
    public R update(@RequestBody PlatUserTagConf platUserTagConf) {
        return R.ok(platUserTagConfService.updateById(platUserTagConf));
    }

    @DeleteMapping("")
    @Operation(description = "删除标签", summary = "删除标签")
    public R delete(@RequestBody PlatUserTagConf platUserTagConf) {
        return R.ok(platUserTagConfService.removeById(platUserTagConf.getId()));
    }
}
